
package ch.comtools.ssh.util;

import java.io.IOException;
import java.nio.ByteBuffer;

import ch.comtools.ssh.datatype.NameList;

/**
 * TypesReader.
 * @author Roger Dudler <roger.dudler@gmail.com>
 * @version $Id$
 */
public class TypeReader {

	/**
	 * Reads name-list bytes from a byte buffer as specified in RFC4253.
	 * @param buffer
	 * @return
	 * @throws IOException
	 */
	public static NameList readNameList(ByteBuffer buffer) {
		int length = buffer.getInt();
		byte[] data = new byte[length];
		buffer.get(data, 0, length);
		String string = new String(data);
		String[] parts = string.split(",");
		NameList list = new NameList();
		for (String part : parts) {
			list.add(part);
		}
		return list;
	}

}
